﻿<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:v="clr-namespace:ShredTheLog.Views;assembly=ShredTheLog.Views"
    xmlns:vm="clr-namespace:ShredTheLog.ViewModels;assembly=ShredTheLog.ViewModels"
    xmlns:cnv="clr-namespace:ShredTheLog.Converters;assembly=ShredTheLog.Converters"
    xmlns:c="clr-namespace:ShredTheLog.Controls;assembly=ShredTheLog.Controls"
    xmlns:tk="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
    >

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="FlowDocumentAutoScrollViewer.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <DataTemplate DataType="{x:Type vm:TextChatRoomViewModel}">
        <Grid x:Name="panel">
            <UIElement.InputBindings>
                <KeyBinding Command="{Binding SendMessageCommand}" Key="{Binding SendMessageGesture.Key}" Modifiers="{Binding SendMessageGesture.Modifiers}"/>    
            </UIElement.InputBindings>
            
            <Grid.RowDefinitions>
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="3*"/>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="1*"/>
            </Grid.ColumnDefinitions>

            <Grid Grid.Column="0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="3*"/>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="1*"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <FlowDocumentScrollViewer Style="{StaticResource FlowDocumentAutoScrollViewerStyle}" VerticalScrollBarVisibility="Auto" Document="{Binding Path=Messages, Converter={x:Static vm:MessagesConverter.Default}}" c:Extensions.UnbindDocumentWhenSettingsUpdated="True"/>
                <GridSplitter Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Stretch" Focusable="False" Height="3"/>
                <DockPanel x:Name="newMessagePanel" Grid.Row="2">
                    <Button DockPanel.Dock="Right" Focusable="False" Command="{Binding SendMessageCommand}">&gt;</Button>
                    <TextBox Text="{Binding Path=NewMessage, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" AcceptsReturn="{Binding Path=SendMessageGesture, Converter={x:Static cnv:MessageCanContainCRConverter.Default}}" TextWrapping="Wrap"/>
                </DockPanel>
                <Border x:Name="loginBanner" Grid.Row="2" CornerRadius="5" BorderThickness="1" BorderBrush="#FFCC66" Background="#FFFFE8" Visibility="Collapsed">
                    <TextBlock Margin="8, 30, 8, 3" TextWrapping="Wrap" TextTrimming="CharacterEllipsis">
                        <Hyperlink Command="{Binding ShowLogInDialogCommand}">
                            <Run Text="{c:LocalizedString s_ClickToLogIn}"/>
                        </Hyperlink>
                    </TextBlock>
                </Border>
            </Grid>

            <GridSplitter Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Stretch" Focusable="False" Width="3"/>

            <tk:DataGrid Grid.Column="2" ItemsSource="{Binding Users}">
                <ItemsControl.ItemContainerStyle>
                    <Style TargetType="{x:Type tk:DataGridRow}">
                        <Setter Property="ContextMenu">
                            <Setter.Value>
                                <ContextMenu c:Extensions.Items="{Binding Converter={x:Static vm:UserMenuItemsConverter.Default}}" DataContext="{Binding RelativeSource={RelativeSource Mode=Self}, Path=PlacementTarget.DataContext}"/>
                            </Setter.Value>
                        </Setter>
                        <Setter Property="ToolTip" Value="{StaticResource UserToolTip}"/>
                    </Style>
                </ItemsControl.ItemContainerStyle>
                <tk:DataGrid.Columns>
                    <tk:DataGridTemplateColumn Header="{x:Null}" CanUserResize="False" SortMemberPath="IsTyping">
                        <tk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock x:Name="isTypingIcon" Foreground="Green" VerticalAlignment="Center" HorizontalAlignment="Center" Text="T" Visibility="Hidden"/>
                                <DataTemplate.Triggers>
                                    <DataTrigger Binding="{Binding IsTyping}" Value="true">
                                        <Setter TargetName="isTypingIcon" Property="Visibility" Value="Visible"/>
                                    </DataTrigger>
                                </DataTemplate.Triggers>
                            </DataTemplate>
                        </tk:DataGridTemplateColumn.CellTemplate>
                    </tk:DataGridTemplateColumn>
                    <tk:DataGridTemplateColumn Header="{x:Null}" CanUserResize="False" SortMemberPath="Gender">
                        <tk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <ContentPresenter Content="{Binding Path=Gender, Mode=OneWay}" HorizontalAlignment="Center"/>
                            </DataTemplate>
                        </tk:DataGridTemplateColumn.CellTemplate>
                    </tk:DataGridTemplateColumn>
                    <tk:DataGridTextColumn Header="{c:LocalizedString s_Name}" Binding="{Binding Path=Name, Mode=OneWay}" Width="*"/>
                </tk:DataGrid.Columns>
            </tk:DataGrid>
        </Grid>
        
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding Credentials}" Value="{x:Null}">
                <Setter TargetName="loginBanner" Property="Visibility" Value="Visible"/>
                <Setter TargetName="newMessagePanel" Property="Visibility" Value="Collapsed"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding IsLoading}" Value="True">
                <Setter TargetName="panel" Property="Cursor" Value="Wait"/>
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>
</ResourceDictionary>